<template>
  <div class="input" :class="{ disabled: disabled }">
    <div class="label" :style="{ width: labelWidth }">
      {{ label }}
    </div>
    <div class="right-wrap">
      <input
        :value="value"
        :type="type"
        @input="handleInput"
        :placeholder="pr"
        :disabled="disabled"
        :style="{ textAlign: inputAlign }"
      />
    </div>
    <div class="line" v-show="line"></div>
  </div>
</template>

<script>
export default {
  name: "Input",
  props: {
    label: String,
    value: String,
    type: {
      type: String,
      default: 'text'
    },
    pr: String,
    line: Boolean,
    labelWidth: {
      type: String,
      default: "60px",
    },
    disabled: Boolean,
    inputAlign: {
      type: String,
      default: "left",
    },
  },
  data() {
    return {};
  },
  methods: {
    handleInput(e) {
      this.$emit("input", e.target.value);
    },
  },
};
</script>

<style lang="scss" scoped>
.input {
  width: 100%;
  height: 45px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  position: relative;
  background: #fff;
  padding: 0 15px;
  margin: auto;

  &.disabled {
    .label,
    input {
      color: #c8c9cc !important;
    }
  }

  .line {
    width: calc(100% - 30px);
    height: 1px;
    background: #f5f5f5;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;
  }

  &::before {
    content: "";
  }

  .label {
    color: #646566;
    font-size: 14px;
  }

  .right-wrap {
    flex: 1;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-left: 15px;

    input {
      width: 100%;
      height: 30px;
      line-height: 30px;
      outline: none;
      border: 0;
      background: transparent;
      color: #323233;
      font-size: 14px;
      box-sizing: border-box;

      &::placeholder {
        color: #c8c9cc;
      }
    }
  }
}
</style>
